package com.ruoyi.manage.controller;


import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.manage.entity.order.OrderFileVo;
import com.ruoyi.manage.service.IOrderFileService;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;


/**
 * 文件上传
 */
@RestController
@RequestMapping("/manage/file")
public class OrderFileController extends BaseController {

    @Autowired
    private IOrderFileService orderFileService;

    @PostMapping("/import")
    public AjaxResult uploadFile(MultipartFile file, String orderId, String fileType) {

        orderFileService.uploadFile(file, orderId, fileType);
        return success("稿件上传成功");
    }

    /**
     * 获取文件信息
     * @param orderId
     * @return
     */
    @GetMapping("/findOrderFile")
    public AjaxResult findOrderFile(@RequestParam("orderId") String orderId) {
        List<OrderFileVo> orderFileList = this.orderFileService.findOrderFile(orderId);
        return success(orderFileList);
    }

    /**
     * 文件下载
     * @param resource 文件标识
     */
    @GetMapping("/orderFileDown/resource")
    public void orderFileDown(HttpServletResponse response, String resource) throws IOException {
        this.orderFileService.orderFileDown(response, resource);
    }


}
